#include <sstream>
#include <fstream>
#include <iostream>

using std::cout;
using std::endl;
using std::string;
using std::stringstream;
using std::istringstream;
using std::ostringstream;
using std::ifstream;

int test0()
{
    //其他类型
    int num1 = 10, num2 = 20;
    stringstream ss;
    //字符串输出流来使用
    ss << "num1= " << num1 << " num2= " << num2; 
    string str = ss.str();//将流中的数据转换为字符串
    cout << "str:" << str << endl;

    //字符串输入流来使用
    string key;
    int val;
    //默认情况下按空格进行分割
    while(ss >> key >> val) {
        cout << key << ", " << val << endl;
    }

    return 0;
}

string int2str(int num) {
    ostringstream oss;
    oss << num;
    return oss.str();
}

//读取配置文件
void readServerConf(const string & filename)
{
    ifstream ifs(filename);
    if(!ifs) {
        cout << "ifstream open file error" << endl;
        return ;
    }

    //每一次读取配置文件中的一行信息
    string line;
    string key, val;
    while(!ifs.eof()) {
        std::getline(ifs, line);
        istringstream iss(line);
        iss >> key >> val;
        cout << key << " --> " << val << endl;
    }
    

    ifs.close();
}

int main()
{
    int num = 1024;
    string snum = int2str(num);
    cout << "snum: " << snum << endl;

    readServerConf("server.conf");
}


